package com.homegoods.discover.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.homegoods.aroutercomment.ARouterPath;
import com.homegoods.discover.R;
import com.homegoods.discover.databinding.DiscoverFragmentDiscoverBinding;
import com.homegoods.videomodule.ui.fragments.FreedomCommunityFragment;
import com.kedll.library.fragment.KBaseFragment;
import com.kedll.library.mvp.BasePresenter;
import com.kedll.library.util.MyUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 *
 * @author QiQi
 */
@Route(path = ARouterPath.PATH_FRAGMENT_DISCOVER)
public class DiscoverFragment extends KBaseFragment<DiscoverFragmentDiscoverBinding, BasePresenter> {

    private List<Fragment> fragments;

    @Override
    public void onUserInvisible() {
        super.onUserInvisible();
        if (fragments != null) {
            ((KBaseFragment) fragments.get(mBinding.viewpager.getCurrentItem())).onUserInvisible();
        }
    }

    @Override
    public void onUserVisible() {
        super.onUserVisible();
        if (fragments != null) {
            ((KBaseFragment) fragments.get(mBinding.viewpager.getCurrentItem())).onUserVisible();
        }
    }

    @Override
    protected void init() {
        super.init();
        String[] titles = getResources().getStringArray(R.array.discover_menu);
        fragments = new ArrayList<>();
        fragments.add(new BestCollectionFragment());
        fragments.add(new FreedomCommunityFragment());
        mBinding.viewpager.setPagingEnabled(false);
        MyUtils.bindViewPagerAndTabLayout(getChildFragmentManager(), fragments, titles, mBinding.viewpager, mBinding.tabLayout);
    }

    @Override
    protected void initEvent(Bundle savedInstanceState) {
        mBinding.discoverMsg.setOnClickListener(v -> ARouter.getInstance()
                .build(ARouterPath.PATH_MESSAGE_LIST)
                .navigation());
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected int getLayout() {
        return R.layout.discover_fragment_discover;
    }

}
